define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'crm/product/index',
                    add_url: 'crm/product/add',
                    edit_url: 'crm/product/edit',
                    del_url: 'crm/product/del',
                    multi_url: 'crm/product/multi',
                    table: 'product',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'product', title: __('Product'),operate:'like'},
                        {field: 'company_id', title: __('Company_id'),operate:'like'},
                      /*  {field: 'describe', title: __('Describe'),operateL:'like'},*/
                        {field: 'web', title: __('Web'),operate:'like'},
                      /*  {field: 'mobile', title: __('Mobile'),operate:'like'},*/
                        {field: 'type', title: __('Type'),searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        /*{field: 'company.company', title: __('Company.company'),operate:'like'},*/
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                /* if(row.status!=1||admin_group_id!=3){
                                     //审核过的数据和不是销售人员隐藏编辑按钮
                                     $(table).data("operate-edit", null);
                                 }*/
                                $(table).data("operate-del", null);
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            }}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});